// pages/settlement/settlement.js
const db = wx.cloud.database();
const commodit = db.collection('Shopping');
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    jieshou: [], //接受传入的参数
    shujuji: [], //获取到的传入参数的物品
    allprice: 0, //总价
    youhui: 0, //优惠
    zongji: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad: function (options) {
      let _id = options._id.split(",")
      let price = parseFloat(options.price) 
      let allprice =price+ parseFloat(options.youhui)
      let youhui = options.youhui
      // 生命周期函数--监听页面加载
      this.setData({
        jieshou: _id,
        allprice: allprice,
        youhui: youhui,
        zongji: price

      })
    },
    async onShow(options) { //监听小程序启动或切前台
      this.huoqu()
    },

    async huoqu() {
      let rat = []
      let res = await (await commodit.get()).data
      for (let i = 0; i < this.data.jieshou.length; i++) {
        for (let j = 0; j < res.length; j++) {
          if (this.data.jieshou[i] == res[j]._id) {
            rat[i] = res[j]
          }
        }
        this.setData({
          shujuji: rat
        })
      }
    }
  }
})